/*
 *  Copyright 2020-2025 the original author or authors.
 *  You cannot use this file unless authorized by the author.
 */

package org.ipig.messaging.rocket.consumer;

import com.alibaba.rocketmq.common.message.MessageExt;
import lombok.Data;
import org.ipig.commons.service.CheckConditionService;
import org.ipig.commons.service.ProcessorService;
import org.ipig.constants.ResultStatus;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 通用消息拉取消费
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id$$
 * @since 1.0
 */
@Data
public class GerericRocketPullConsumer extends AbstractRocketPullConsumer {
    /**
     * 检查执行条件服务
     */
    @Autowired(required = false)
    private CheckConditionService checkConditionService;

    //处理消息服务
    @Autowired(required = false)
    private ProcessorService<List<MessageExt>, ResultStatus> processorService;

    @Override
    public boolean checkExecuteCondition() {
        if (checkConditionService != null) {
            return checkConditionService.checkCondition();
        }
        return true;
    }


    @Override
    public ResultStatus doProcess(List<MessageExt> msgList) {
        if (processorService != null) {
            return processorService.process(msgList);
        }
        return ResultStatus.FAILURE;
    }
}
